// pages/all/business/business.js
const time = require('../../util/uts.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leixing: '待处理', //下拉类型
    select: false,
    dadada: 1,
    curordernum: '',
    array: []
  },

  refresh() {
    this.taskList()
  },

  // 下拉类型选择
  bindShowMsg: function () {
    this.setData({
      select: !this.data.select
    })
  },

  // 变更类型选择
  mySelect: function (e) {
    var name = e.currentTarget.dataset.name
    this.setData({
      leixing: name,
      select: false
    })

    if(name == "待处理")
      this.taskList()
    if(name == "已处理")
      this.taskList2()
  },

  // 查看订单号面事件
  chakan1: function (e) {
    var that = this;
    var array = this.data.array;
    // console.log(array);
    // var idss = e.currentTarget;
    // console.log(idss)
    var id = e.currentTarget.dataset.index;
    // console.log(id);
    // 获取订单号
    var orid = array[id].ordernum;

    var curstatus = array[id].status;

    console.log(curstatus);

    that.setData({
      'curordernum': orid
    })


    //认领流程
    if (app.globalData.forsysuser_id == 2) {

      if (curstatus != '待认领' && curstatus != '处理中') {
        wx.showModal({
          title: '提示',
          content: '请等待预审...',
          confirmText: "确定",
          showCancel: false,
        })
        return;
      }

      //认领后改变状态
      wx.request({
        url: app.globalData.wancheURL + 'upWCCOMOrderStatusForNum',
        method: 'POST',
        header: {
          "Content-Type": "application/x-www-form-urlencoded",

        },
        data: {
          ordernum: orid,
          status: '处理中'
        },

        success(res) {
          console.log(that.data.curordernum);
          wx.navigateTo({
            url: '/pages/order/order/order?ordernum=' + that.data.curordernum
          });
        }
      })

      return;
    }

    console.log(orid);
    wx.navigateTo({
      url: '../showimg/showimg?orid=' + orid,
    })

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    that.setData({
      userId: app.globalData.userInfo.id
      // userId: 1000396
    })

    that.taskList();
  },

  taskList() {
    let that = this;

    wx.request({
      url: app.globalData.serviceUrl + '/wcComOrder/myTaskList',
      data: {
        userId: that.data.userId
      },
      method: "GET",
      success(res) {
        console.log(res);

        that.setData({
          array: res.data
        })
      },
      error(err) {
        console.error(err);
      }
    })

  },

  taskList2() {
    let that = this;

    wx.request({
      url: app.globalData.serviceUrl + '/wcComOrder/myTaskList4History',
      data: {
        userId: that.data.userId
      },
      method: "GET",
      success(res) {
        console.log(res);

        that.setData({
          array: res.data
        })
      },
      error(err) {
        console.error(err);
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // let that = this;

    // wx.request({
    //   url: app.globalData.serviceUrl + '/wcComOrder/myTaskList',
    //   data: {
    //     userId: that.data.userId
    //   },
    //   method: "GET",
    //   header: {
    //     'content-type': 'application/x-www-form-urlencoded'
    //   },
    //   success(res) {
    //     console.log(res);
    //     that.setData({
    //       array: res.data
    //     })

    //   }
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})